package cn.gson.crm.control.office;

import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.StringUtils;

import cn.gson.crm.control.base.BaseServlet;
import cn.gson.crm.model.dao.OfficeDao;
import cn.gson.crm.model.po.OfficePo;
@WebServlet("/office/manager")
public class OfficeManagerServlet extends BaseServlet{
	private OfficeDao officeDao = new OfficeDao();
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String nowpage = request.getParameter("nowpage");
		String stuname = request.getParameter("stuname");
		String stucompany = request.getParameter("stucompany");
		int stuid = 0 ;
		if(!StringUtils.isNullOrEmpty(stuname)){
			stuid = officeDao.getStuId(stuname);
		}
		if(nowpage == null){
			nowpage = "1";
			}
		int page = officeDao.getOfficePageSum();
		List<OfficePo> officePoList = officeDao.getAllOfficeList(Integer.parseInt(nowpage),stuid,stucompany);
		request.setAttribute("officePoList", officePoList);
		request.getSession().setAttribute("pageSum", page);
		request.getSession().setAttribute("nowpage", nowpage);
		forward("office/office_manager.jsp");
	}
	
	@Override
	protected void post(HttpServletRequest request, HttpServletResponse response) throws Exception {
		get(request, response);
	}
	

}
